<template>
	<view class="page">
		<view style="width: 100%;height: 100%; background: url('http://49.232.14.51:9000/friend/lg-bg.png');background-repeat: no-repeat;background-size: 100% 100%;overflow: hidden;">	
			<view class="" style="color: white;text-align: center;margin-top: 20%;">
				<view class="" style="">
					<image src="http://49.232.14.51:9000/friend/logo.jpg" style="width: 80px;height: 80px;border-radius: 15px;"></image>
				</view>
				<view class="" style="text-align: center;">
					<view class="" style="height: 0px;margin-right: 60%;">
						<image src="../../../static/img/bj-1.png" style="width: 6px;height: 6px;"></image>
					</view>
					<view class="title">
						<view class="">
							在道友圈
						</view>
					</view>
					<view class="title">
						<view class="">
							认识新的自己
						</view>
					</view>
					<view class="" style="font-size: 15px;">
						New Friend, New Life
					</view>
					<view class="" style="height: 0px;margin-left: 60%;">
						<image src="../../../static/img/bj-3.png" style="width: 10px;height: 10px;"></image>
					</view>
				</view>
			</view>
			<button class="login" withCredentials="true" lang="zh_CN" @click="wxLogin">快速登录</button>
		</view>	
	</view>
</template>

<script>
	export default {
		onLoad() {
			// 获取用户信息
			var userInfo = uni.getStorageSync("globalUser");
			if(userInfo != null && userInfo != undefined &&
			userInfo.nickname != null && userInfo.nickname != undefined){
				if(userInfo.sex != null && userInfo.sex != ''){
					if(userInfo.honors != null && userInfo.honors != ''){
						uni.switchTab({
							url: '../../main/main/main'
						})
					}else {
						uni.navigateTo({
							url: "../honor/honor"
						});
					}
				}else {
					uni.navigateTo({
						url: "../memInfo/memInfo"
					});
				}
			}
		},
		methods: {
			// 实现在微信小程序端的微信登录
			wxLogin() {
				var me = this;
				// 获取用户信息
				uni.getUserProfile({
					desc: "Wexin",
					success: infoRes => {
						// console.log(e);
						// 通过微信开发能力，获得微信用户的基本信息
						var userInfo = infoRes.userInfo;
						// 实现微信登录
						uni.login({
							provider: "weixin",
							success:(loginResult) => {
								console.log(loginResult);
								// 获得微信登录的code：授权码
								var code = loginResult.code;
								// 设置登录到哪个对于的微信小程序，大家可以根据自己的后端去实现业务参数
								// [0:NEXT超英预告][1:超英预告][2:NEXT学院电影预告]
								var loginToWhichMP = 1;
								uni.request({
									url: this.$mConfig.baseUrl + "/mpWXLogin/" + code,
									data: {
										"faceImage": userInfo.avatarUrl,
										"nickname": userInfo.nickName,
										"whichMP": loginToWhichMP
									},
									method: "POST",
									success(userResult) {
										console.log(userResult);
										var userInfo = userResult.data.data;
										// 保存用户信息到全局的缓存中
										uni.setStorageSync("globalUser", userInfo);
										// 切换页面跳转，使用tab切换的api
										if(userInfo.sex != null && userInfo.sex != ''){
											if(userInfo.honors != null && userInfo.honors != ''){
												uni.switchTab({
													url: '../../main/main/main'
												})
											}else {
												uni.navigateTo({
													url: "../honor/honor"
												});
											}
										}else {
											uni.navigateTo({
												url: "../memInfo/memInfo"
											});
										}
									}
								});
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.page {
		width: 100%;
		height: 100%;
	}
	button {
		background-color: #5080FE;
		border-radius: 60upx;
		width: 80%;
		margin-top: 50%;
	}
	.title {
		font-size: 30px;
		font-weight: bold;
	}
</style>
